package com.bsoft.gol.editor.controller;


import hcn.util.BaseResponse;
import com.bsoft.gol.editor.editor.EditorWidgetClass;
import com.bsoft.gol.editor.editor.request.WidgetReq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.bsoft.gol.editor.service.EditorWidgetClassApi;

import java.util.List;

/**
 *
 * @author lxy
 * @date 2019/6/18
 */
@Controller
@RequestMapping(value = "/api/auth/editorWidgetClass")
public class EditorWidgetController {

    @Autowired
    private EditorWidgetClassApi editorWidgetClassApi;

    @RequestMapping("/addOrEdit")
    @ResponseBody
    public BaseResponse<String> addOrEdit(@RequestBody WidgetReq req) {
        BaseResponse<String> response = new BaseResponse<>();
        String classId = editorWidgetClassApi.addOrEdit(req.getClassId(), req.getClassName());
        response.setData(classId);
        return response;
    }

    @RequestMapping("/list")
    @ResponseBody
    public BaseResponse<List<EditorWidgetClass>> list() {
        BaseResponse<List<EditorWidgetClass>> response = new BaseResponse<>();
        List<EditorWidgetClass> list = editorWidgetClassApi.list();
        response.setData(list);
        return response;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public BaseResponse<List<EditorWidgetClass>> delete(@RequestBody WidgetReq req) {
        BaseResponse<List<EditorWidgetClass>> response = new BaseResponse<>();
        editorWidgetClassApi.delete(req.getClassId());
        return response;
    }

}
